$(function () {

    iniList();
    bindClick();

})

function iniList() {
    $("#roleList").datagrid({
        url:'/admin/role/query',
        method:'post',
        pagination:true,
        rownumbers: true,
        local:"zh_CN",
        pageNumber:1,
        pageSize:10,
        singleSelect:true,
        queryParams: {
        },
        columns:[[
            {field:'id',title:'角色id',width:50,hidden:true},
            {field:'roleName',title:'角色名称',width:150},
            {field:'roleValue',title:'角色值',width:100},
        ]],
        loadFilter: function(data){
            if (data.code == '0000'){
                return data.retData.roles;
            } else {
                return [];
            }
        },
        onBeforeLoad: function (param) {

        }
    });
}



function bindClick() {
    $("#addBtn").on("click",function (){
        $('#win').window({
            width:600,
            height:400,
            modal:true,
            title:"角色增加",
            href:"/view/biz/role/addRole.html"
        });
    })

    $("#editBtn").on("click",function (){
        $('#win').window({
            width:600,
            height:400,
            modal:true,
            title:"角色编辑",
            href:"/view/biz/role/editRole.html"
        });
    })

    $("#delBtn").on("click",function (){

        $.messager.confirm('删除确认','确认是否删除',function (r){
            if(r) {
                var selectedObj = $("#roleList").datagrid("getSelected");
                if(Kit.isEmpty(selectedObj)) {
                    $.messager.alert("帮助提示","请选中要删除的行");
                    return false;
                }

                ui.request({
                    url:"/admin/role/delete",
                    data:{"id":selectedObj.id},
                    success:function (rtn) {
                        if(rtn.code != undefined && rtn.code !== "0000"){
                            $.messager.alert(rtn.msg,rtn.desc);
                        }
                        $("#roleList").datagrid("reload",{});
                    }
                })
            }
        });
    })

    $("#bindBtn").on("click",function () {
        $('#win').window({
            title:"资源绑定",
            width:600,
            height:400,
            modal:true,
            href:"/view/biz/role/bindResource.html"
        });
    });
}


// 初始化日期控件
function iniDate(flag) {
    $('#dd').datebox({
        required:true,
        onSelect: function(date){
            var dateStr = date.Format("yyyy-MM-dd");
            if(flag == 1) {
                pushOrReceive(dateStr);
            }else if(flag == 2) {
                warnPushOrReceive(dateStr);
            }

            statistics(dateStr);
        }
    });
    var date = new Date();
    date.setDate(date.getDate()-1);//设置天数 -1 天
    var dateStr = date.Format("yyyy-MM-dd");
    $('#dd').datebox('setValue', dateStr);

}
